package com.topisv.tms.task;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.topisv.tms.entity.ediOrder.EdiOrderVO;
import com.topisv.tms.service.EdiOrderService;
import com.topisv.tms.utils.ThreadPool;

@Component
@Lazy(false)
public class EdiOrderOutScopeProvider implements InitializingBean {

	private Logger logger = LoggerFactory.getLogger(getClass());
	private BlockingQueue<EdiOrderVO> tasks = new ArrayBlockingQueue<EdiOrderVO>(2000);
	@Autowired
	private EdiOrderService ediOrderService;

	@Scheduled(cron = "0/30 * * * * *")
	public void executor() {
		try {
			List<EdiOrderVO> data = ediOrderService.findListByRlIsNull();
			for (EdiOrderVO task : data) {
				tasks.put(task);
			}
		} catch (Exception e) {
			logger.error("error.", e);
		}
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		//开启线程池
		ThreadPool pool = ThreadPool.getThreadPool();
		pool.execute(new EdiOrderOutScope(tasks,ediOrderService));
		pool.destroy();
	}
}
